<?php

/*
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */

class index_controller extends office_controller {

    function index_action() {
        $where = "stype=1";
        $dclasses = $this->obj->DB_select_all("desc_class", $where, "*");
        $this->yunset("dclasses", $dclasses);

        $where = "is_nav=0";
        $order = " order by sort asc";
        $descrows = $this->obj->DB_select_all("description", $where . $order, "*");
        $this->yunset("descrows", $descrows);
        $this->yun_tpl(array('index'));
    }

    function list_action() {
        $where = "stype=1";
        $dclasses = $this->obj->DB_select_all("desc_class", $where, "*");
        $this->yunset("dclasses", $dclasses);

        $where = "is_nav=0";
        $order = " order by sort asc";
        $descrows = $this->obj->DB_select_all("description", $where . $order, "*");
        $this->yunset("descrows", $descrows);

        $id = $_GET['id'];
        $where = "id=" . $id;
        $one = $this->obj->DB_select_once("description", $where . $order, "*");
        $this->yunset("one", $one);
        $this->yunset("id", $id);
        $this->yun_tpl(array('list'));
    }
    
    function rc_action() {
        /*$id = $_GET['id'];
        $where = "id=" . $id;
        $oneItem = $this->obj->DB_select_once("description", $where , "*");
        $this->yunset("oneItem", $oneItem);
        $this->yunset("id", $id);*/
        $this->yun_tpl(array('item'));
    }
    
    function area_action() {
        $where="1";
        $where.=" and UNIX_TIMESTAMP(`starttime`)<'".time()."' and UNIX_TIMESTAMP(`endtime`)>'".time()."'";
        $rows=$this->obj->DB_select_all("gaoduan",$where,"*");
        $this->yunset("rows", $rows);
        $this->yun_tpl(array('arealist'));
    }
    
    function areadetail_action() {
        $id = $_GET['id'];
        $where = "id=" . $id;
        $one = $this->obj->DB_select_once("gaoduan", $where, "*");
        $this->yunset("Info", $one);

        $where = "zid=".$id;
        $coms=$this->obj->DB_select_all("gaoduan_com",$where." limit 10","*");
        foreach($coms as $k=>$val){
            if($this->uid!=$val['uid'])
            {
                $coms[$k]['phone']=preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $val['phone']);
                $coms[$k]['name'] =substr_replace($val['name'], '****', 3, 10);
            }
        }
        $this->yunset("coms", $coms);
        $this->yun_tpl(array('areashow'));
    }

    function reserve_action() {
        $id = $_GET['id'];
        $where = "id=" . $id;
        $one = $this->obj->DB_select_once("gaoduan", $where, "*");
        $this->yunset("Info", $one);
        $this->yunset("uid",$this->uid);

        $where = "zid=".$id;
        $coms=$this->obj->DB_select_all("gaoduan_com",$where." order by id desc limit 10","*");
        foreach($coms as $k=>$val){
            if($this->uid!=$val['uid'])
            {
                $coms[$k]['phone']=preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $val['phone']);
                $coms[$k]['name'] =substr_replace($val['name'], '****', 3, 10);
            }
        }
        $this->yunset("coms", $coms);
        $this->yun_tpl(array('areareserve'));
    }

    function save_action() {
        extract($_POST);
        $id=$_POST['id'];
        unset($_POST['id']);
        if($_POST['time']){
            $times=@explode('~',$_POST['time']);
            $_POST['starttime']=$times[0];
            $_POST['endtime']=$times[1];
            unset($_POST['time']);
        }
        $_POST['zid']=$id;
        $nbid=$this->obj->insert_into("gaoduan_com",$_POST);
       echo "<script>location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
    }
}

?>